﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Diagnostics;

namespace LowLevelGraphics.ColorSpaces
{
    /// <summary>
    /// RGB Channel
    /// </summary>
    public enum RGBChannel
    {
        /// <summary>
        /// 
        /// </summary>
        R = 0,
        /// <summary>
        /// 
        /// </summary>
        G = 1,
        /// <summary>
        /// 
        /// </summary>
        B = 2
    }

    /// <summary>
    /// 
    /// </summary>
    [DebuggerDisplay("R: {m_R}, G: {m_G}, B: {m_B}")]
    public class RGB : AbstractColorSpace
    {
        protected int m_R = 0;
        protected int m_G = 0;
        protected int m_B = 0;

        /// <summary>
        /// primary constructor
        /// </summary>
        /// <param name="_color"></param>
        public RGB(Color _color)
            : base(_color)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HSI"/> class.
        /// </summary>
        /// <param name="_H">The _ H.</param>
        /// <param name="_S">The _ S.</param>
        /// <param name="_I">The _ I.</param>
        public RGB(int _R, int _G, int _B)
        {
            m_R = _R;
            m_G = _G;
            m_B = _B;
        }

        /// <summary>
        /// used by clone to create a deep copy
        /// </summary>
        /// <param name="_hsi"></param>
        internal RGB(RGB _rgb)
        {
            m_Color = _rgb.m_Color;
            this.m_R = _rgb.m_R;
            this.m_G = _rgb.m_G;
            this.m_B = _rgb.m_B;
        }

        /// <summary>
        /// Enable casting into operator
        /// </summary>
        /// <param name="_color"></param>
        /// <returns></returns>
        public static explicit operator RGB(Color _color)
        {
            return new RGB(_color);
        }

        /// <summary>
        /// Gets or sets H
        /// </summary>
        public int R
        {
            get { return m_R; }
            set { m_R = value; }
        }

        /// <summary>
        /// Gets or sets S
        /// </summary>
        public int G
        {
            get { return m_G; }
            set { m_G = value; }
        }

        /// <summary>
        /// Gets or sets B
        /// </summary>
        public int B
        {
            get { return m_B; }
            set { m_B = value; }
        }

        /// <summary>
        /// used to transform color into this color space
        /// </summary>
        protected override void CalcValues()
        {
            //nothing todo here...
            m_R = m_Color.R;
            m_G = m_Color.G;
            m_B = m_Color.B;
        }

        /// <summary>
        /// transforms back to RGB color space
        /// </summary>
        /// <returns></returns>
        public override Color ToColor()
        {
            return Color.FromArgb(m_R, m_G, m_B);
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return string.Format("Color R = {0}, G = {1}, B = {2}", m_R, m_G, m_B);
        }

        /// <summary>
        /// Gets the values.
        /// </summary>
        /// <returns></returns>
        public override object[] GetValues()
        {
            return new object[] { m_R, m_G, m_B };
        }

        /// <summary>
        /// Sets the values.
        /// </summary>
        /// <param name="_aObject">The _a object.</param>
        public override void SetValues(object[] _aObject)
        {
            this.m_R = (int)_aObject[0];
            this.m_G = (int)_aObject[1];
            this.m_B = (int)_aObject[2];
        }

        /// <summary>
        /// Used to create a deep copy
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new RGB(this);
        }
    }
}
